package com.syscom.server.action;

import java.util.HashMap;
import java.util.Properties;

import com.syscom.sar.server.constant.QDCActFuncConstant;
import com.syscom.shared.server.action.Action;

public class ActionFactory {
	private static Properties mActionMapping = null;
	private static HashMap<String, Action> mInstanceMap = new HashMap<String, Action>();
	
	// ACTADD 新增Action時, 須於此新增
	static {
		mActionMapping = new Properties();
		
		// QD
		mActionMapping.put(QDCActFuncConstant.QTA_ACTION_ID, QDCActFuncConstant.QTA_ACTION_PATH);
		
		// QC
		mActionMapping.put(QDCActFuncConstant.QC_ACTION_ID, QDCActFuncConstant.QC_ACTION_PATH);
	}
	
	public static Action getAction(String strActId) throws Exception {
		Action action = null;
		if (!mInstanceMap.containsKey(strActId)) {
			String sActClassPath = mActionMapping.getProperty(strActId);
			action = (Action) Class.forName(sActClassPath).newInstance();
			mInstanceMap.put(strActId, action);
		}
		else {
			action = mInstanceMap.get(strActId);
		}
		return action;
	}
}